package com.zhouyu.gamecommunity.controller;

import cn.hutool.core.util.StrUtil;
import com.zhouyu.gamecommunity.entity.Result;
import com.zhouyu.gamecommunity.entity.User;
import com.zhouyu.gamecommunity.entity.queryParams.LoginParam;
import com.zhouyu.gamecommunity.service.CommonService;
import com.zhouyu.gamecommunity.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @description user
 * @author zhouyu
 * @date 2025-06-07
 */
@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Resource
    private UserService userService;
    @Resource
    private CommonService commonService;

    @PostMapping("/login")
    public Result<User> userLogin(@RequestBody LoginParam loginParam) {
        return userService.userLogin(loginParam);
    }

    @PostMapping("/register")
    public Result<Integer> userRegister(@RequestBody LoginParam loginParam) {
        return userService.userRegister(loginParam);
    }

    @GetMapping("/{userId}")
    public Result<User> getUserById(@PathVariable("userId") String userId) {
        return userService.getUserById(userId);
    }

    @GetMapping("/verifyCode/{userId}")
    public Result<String> getVerifyCode(@PathVariable("userId") String userId) {
        String verifyCode = commonService.createVerifyCode(userId);
        String result = "【游戏社区攻略助手】您的验证码是{}，该验证码3分钟内有效，请勿泄露于他人！";
        return Result.success(StrUtil.format(result, verifyCode));
    }

    @PostMapping("/update")
    public Result<Integer> updateUserById(@RequestBody User user) {
        return userService.updateUserById(user);
    }

}